// source --> http://www.tsurishi.info/tblog/wp-content/plugins/simple-download-monitor/js/sdm_wp_scripts.js?ver=4.9.8 // Simple Download Monitor frontend scripts jQuery(document).ready(function ($) { // Populate all nested titles and links $('li.sdm_cat').each(function () { var $this = $(this); this_slug = $this.attr('id'); this_id = $this.children('.sdm_cat_title').attr('id'); // Run ajax $.post( sdm_ajax_script.ajaxurl, { action: 'sdm_pop_cats', cat_slug: this_slug, parent_id: this_id }, function (response) { // Loop array returned from ajax function $.each(response.final_array, function (key, value) { // Populate each matched post title and permalink $this.children('.sdm_placeholder').append('' + value['title'] + ''); }); $this.children('span').append(''); } ); }); // Hide results on page load $('li.sdm_cat').children('.sdm_placeholder').hide(); // Slide toggle for each list item $('body').on('click', '.sdm_cat_title', function (e) { // If there is any html.. then we have more elements if ($(this).next().html() != '') { $(this).next().slideToggle(); // toggle div titles } }); // Download buttons with terms or captcha has this class applied to it $('.sdm_download_with_condition').on('click', function (e) { e.preventDefault(); $(this).closest('form').trigger('submit'); }); // Check if terms checkbox is enabled. if ($('.sdm-termscond-checkbox').length) { $.each($('.sdm-termscond-checkbox'), function () { if (!$(this).is(':checked')) { var cur = $(this).children(':checkbox'); var btn = $(cur).closest('form').find('a.sdm_download,a.sdm_download_with_condition'); $(btn).addClass('sdm_disabled_button'); } }); $.each($('.sdm-download-form'), function () { var form = $(this); form.on('submit', function () { if ($('.agree_termscond', form).is(':checked')) { $('.sdm-termscond-checkbox', form).removeClass('sdm_general_error_msg'); return true; } else { $('.sdm-termscond-checkbox', form).addClass('sdm_general_error_msg'); } return false; }); }); $.each($('.agree_termscond'), function () { var element = $(this); var form = element.closest('form'); element.on('click', function () { if (element.is(':checked')) { $('.sdm_download_with_condition', form).removeClass('sdm_disabled_button'); $('.sdm-termscond-checkbox', form).removeClass('sdm_general_error_msg'); } else { $('.sdm_download_with_condition', form).addClass('sdm_disabled_button'); $('.sdm-termscond-checkbox', form).addClass('sdm_general_error_msg'); } }); }); } });